﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LotteryVote.Entity;
using System.Data.SqlClient;

namespace LotteryVote.Data
{
    public class DefaultUpperLimitDataAccess : DataBase
    {
        public void Insert(DefaultUpperLimit limit)
        {
            string sql = string.Format(@"INSERT INTO {0} ({1},{2}) VALUES (@{1},@{2}) SELECT IDENT_CURRENT('{0}')",
                DefaultUpperLimit.TABLENAME, DefaultUpperLimit.GAMEPLAYWAYID, DefaultUpperLimit.LIMITAMOUNT);
            object id = base.ExecuteScalar(sql, new SqlParameter(DefaultUpperLimit.GAMEPLAYWAYID, limit.GamePlayWayId),
                new SqlParameter(DefaultUpperLimit.LIMITAMOUNT, limit.LimitAmount));
            limit.LimitId = Convert.ToInt32(id);
        }

        public DefaultUpperLimit GetDefaultUpperLimit(int gameplaywayId)
        {
            string sql = string.Format(@"SELECT * FROM {0} WHERE {1}=@{1}", DefaultUpperLimit.TABLENAME, DefaultUpperLimit.GAMEPLAYWAYID);
            return base.ExecuteEntity<DefaultUpperLimit>(sql, new SqlParameter(DefaultUpperLimit.GAMEPLAYWAYID, gameplaywayId));
        }
    }
}
